package common

import (
	"ginblog/model"
	"ginblog/utils/errmsg"
	"github.com/gin-gonic/gin"
)

type RegisterBase struct {
	UserName string
	LoginBase
}

func (reg *RegisterBase) RegisterSuccess(c *gin.Context) {
	SuccessJson(c, errmsg.SUCCESS, []interface{}{})
}

func (reg *RegisterBase) RegisterFail(code int, c *gin.Context) {
	SuccessJson(c, code, []interface{}{})
}

func (reg *RegisterBase) IsSetUserName() bool {
	return reg.UserName != ""
}

func (reg *RegisterBase) IsPhoneRepeat(phone string) bool {
	result := model.Db.Find(model.Blog{
		Phone: phone,
	})
	if result.RowsAffected > 0 {
		return true
	}
	return false
}

func (reg *RegisterBase) IsEmailRepeat(email string) bool {
	result := model.Db.Find(model.Blog{
		Email: email,
	})
	if result.RowsAffected > 0 {
		return true
	}
	return false
}
